package com.xmkj.bearbiz.home;

import android.content.Intent;
import android.view.View;
import android.widget.RelativeLayout;

import com.common.Entity.HtmlEntity;
import com.common.mvp.BaseMvpActivity;
import com.common.mvp.BasePresenter;
import com.common.retrofit.method.GetHtmlMethods;
import com.common.retrofit.subscriber.CommonSubscriber;
import com.common.retrofit.subscriber.SubscriberListener;
import com.common.utils.EmptyUtils;
import com.xmkj.bearbiz.BaseUrlURLActivity;
import com.xmkj.bearbiz.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Create by leo
 * 创建日期：2018/5/29
 * 描述：
 */

public class NewHandActivity extends BaseMvpActivity {
    @BindView(R.id.rl_question)
    RelativeLayout rlQuestion;
    @BindView(R.id.rl_rule)
    RelativeLayout rlRule;
    @BindView(R.id.rl_aboat)
    RelativeLayout rlAboat;
    @BindView(R.id.rl_service)
    RelativeLayout rlService;
    @BindView(R.id.rl_baozhang)
    RelativeLayout rlBaozhang;
    private HtmlEntity entity;

    @Override
    protected BasePresenter createPresenterInstance() {
        return null;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_newhand;
    }

    @Override
    protected void onViewCreated() {

    }

    @Override
    protected void doLogicFunc() {
        goGetHtml();
        attachClickListener(rlAboat);
        attachClickListener(rlBaozhang);
        attachClickListener(rlQuestion);
        attachClickListener(rlRule);
        attachClickListener(rlService);
    }

    @Override
    protected void onViewClicked(View view) {
        if(view.getId()==rlAboat.getId()){
            if (EmptyUtils.isNotEmpty(entity.peisong)) {
                Intent intent1 = new Intent(context, BaseUrlURLActivity.class);
                intent1.putExtra(BaseUrlURLActivity.MAIN_URL, entity.peisong);
                intent1.putExtra(BaseUrlURLActivity.TITILE, "配送商品");
                context.startActivity(intent1);}

//            }
        }else if(rlBaozhang.getId()==view.getId()){
            if (EmptyUtils.isNotEmpty(entity.baozhang)) {
                Intent intent1 = new Intent(context, BaseUrlURLActivity.class);
                intent1.putExtra(BaseUrlURLActivity.MAIN_URL, entity.baozhang);
                intent1.putExtra(BaseUrlURLActivity.TITILE, "保障");
                context.startActivity(intent1);}
        }else if(rlQuestion.getId()==view.getId()){
            if (EmptyUtils.isNotEmpty(entity.wenti)) {
                Intent intent1 = new Intent(context, BaseUrlURLActivity.class);
                intent1.putExtra(BaseUrlURLActivity.MAIN_URL, entity.wenti);
                intent1.putExtra(BaseUrlURLActivity.TITILE, "常见问题");
                context.startActivity(intent1);}
        }else if(rlRule.getId()==view.getId()){
            if (EmptyUtils.isNotEmpty(entity.guize)) {
                Intent intent1 = new Intent(context, BaseUrlURLActivity.class);
                intent1.putExtra(BaseUrlURLActivity.MAIN_URL, entity.guize);
                intent1.putExtra(BaseUrlURLActivity.TITILE, "规则");
                context.startActivity(intent1);}
        }else if(rlService.getId()==view.getId()){
            if (EmptyUtils.isNotEmpty(entity.xieyi)) {
                Intent intent1 = new Intent(context, BaseUrlURLActivity.class);
                intent1.putExtra(BaseUrlURLActivity.MAIN_URL, entity.xieyi);
                intent1.putExtra(BaseUrlURLActivity.TITILE, "服务协议");
                context.startActivity(intent1);}
        }
    }

    private void goGetHtml() {
        CommonSubscriber<HtmlEntity> subscriber = new CommonSubscriber<>(new SubscriberListener() {
            @Override
            public void onNext(Object o) {
                dismissProgressDialog();
                entity = (HtmlEntity) o;

            }

            @Override
            public void onError(String e, int code) {
                dismissProgressDialog();
                showToastMsg(e);
            }
        });
        GetHtmlMethods.getInstance().h5(subscriber, uid, hashid);
        rxManager.add(subscriber);
    }

    @Override
    protected void setNavigation() {
        setNavigationBack("新手");
    }



    @Override
    public void bindKnife() {
        ButterKnife.bind(this);
    }
}
